package com.ruoyi.business.controller;

import com.ruoyi.business.domain.RequipmentMaintRec;
import com.ruoyi.business.service.IRequipmentMaintRecService;
import com.ruoyi.business.vo.RequipmentMaintRecListVO;
import com.ruoyi.business.vo.StatisticVo;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备维护记录Controller
 * 
 * @author qiancheng
 * @date 2025-09-29
 */
@RestController
@RequestMapping("/business/rec")
public class RequipmentMaintRecController extends BaseController
{
    @Autowired
    private IRequipmentMaintRecService requipmentMaintRecService;

    /**
     * 查询设备维护记录列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(RequipmentMaintRec requipmentMaintRec)
    {
        startPage();
        List<RequipmentMaintRec> list = requipmentMaintRecService.selectRequipmentMaintRecList(requipmentMaintRec);
        return getDataTable(list);
    }

    /**
     * 导出设备维护记录列表
     */
    @Anonymous
    @PostMapping("/export")
    public void export(HttpServletResponse response, RequipmentMaintRec requipmentMaintRec)
    {
        List<RequipmentMaintRec> list = requipmentMaintRecService.selectRequipmentMaintRecList(requipmentMaintRec);
        ExcelUtil<RequipmentMaintRec> util = new ExcelUtil<RequipmentMaintRec>(RequipmentMaintRec.class);
        util.exportExcel(response, list, "设备维护记录数据");
    }

    /**
     * 获取设备维护记录详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(requipmentMaintRecService.selectRequipmentMaintRecById(id));
    }

    /**
     * 新增设备维护记录
     */
    @Anonymous
    @RepeatSubmit
    @PostMapping
    public AjaxResult add(@RequestBody RequipmentMaintRec requipmentMaintRec)
    {
        return toAjax(requipmentMaintRecService.insertRequipmentMaintRec(requipmentMaintRec));
    }

    /**
     * 修改设备维护记录
     */
    @Anonymous
    @PutMapping
    public AjaxResult edit(@RequestBody RequipmentMaintRec requipmentMaintRec)
    {
        return toAjax(requipmentMaintRecService.updateRequipmentMaintRec(requipmentMaintRec));
    }

    /**
     * 删除设备维护记录
     */
    @Anonymous
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(requipmentMaintRecService.deleteRequipmentMaintRecByIds(ids));
    }

    /**
     * 删除设备维护记录
     */
    @Anonymous
    @PostMapping("/remove")
    public AjaxResult remove(@RequestParam("id") Long id)
    {
        return toAjax(requipmentMaintRecService.deleteRequipmentMaintRecById(id));
    }

    /**
     * 查询维养记录列表（带设备信息）
     */
    @Anonymous
    @GetMapping("/getMaintRecList")
    public AjaxResult getMaintRecList(RequipmentMaintRec requipmentMaintRec) {
        List<RequipmentMaintRecListVO> list = requipmentMaintRecService.selectMaintRecList(requipmentMaintRec);
        return AjaxResult.success(list);
    }


    /**
     * 查询设备维护次数信息
     * @param year 年份
     * @return 设备维护次数列表
     */
    @GetMapping("/getMaintCount")
    public AjaxResult getEquipmentMaintenanceCount(@RequestParam Integer year,
                                                   @RequestParam String rackId) {
        return success(requipmentMaintRecService.getEquipmentMaintenanceCount(year,rackId));
    }

    /**
     * 首页->>数据对比
     */
    @GetMapping("/getMonthly")
    public TableDataInfo getMonthlyStatistics() {
        List<StatisticVo> data = requipmentMaintRecService.getFullMonthStatistic();
        return getDataTable(data);
    }

}
